*** Settings ***
Documentation       通过ipmi接口测试openUBMC的BMC软件名称
Resource            ../../test_function/ipmi/ipmi.robot
Library             OperatingSystem
Library             BuiltIn

Test Tags           Ipmi_BMC_Name

*** Variables ***
${get_bmc_name}             raw 0x30 0x92 0xdb 0x07 0x00 0x45
${expected_rc}              ${0}
${max_retries}              ${3}    # 最大重试次数
${retry_interval}           1s      # 重试间隔
${expected_output}          db 07 00

*** Test Cases ***
Get IPMI BMC Name
    [Documentation]    带认证的IPMI测试BMC名称
    [Tags]  Get_BMC_Name_Via_IPMI
    ${result}=    Run Keyword And Return Status    Retry Get BMC Name
    Should Be True    ${result}    msg=Failed to get BMC name after ${max_retries} retries

*** Keywords ***
Retry Get BMC Name
    [Documentation]    重试获取BMC名称
    FOR    ${i}    IN RANGE    ${max_retries}
        ${rc}    ${output}=    Run External Ipmi Command    ${get_bmc_name}
        Log    Attempt ${i+1}: Command Output: ${output}
        Run Keyword If    ${rc} == ${expected_rc} and '${expected_output}' in '${output}'
        ...    Return From Keyword    ${True}
        ...    ELSE IF    ${i} < ${max_retries}-1
        ...    Run Keywords
        ...    Log    Retrying in ${retry_interval}...    level=WARN
        ...    AND    Sleep    ${retry_interval}
    END
    Fail    Failed to get BMC name after ${max_retries} attempts